﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework;

namespace GameTank
{
    public class MySprite2D : VisibleGameEntity
    {
        private static Texture2D[][] textures;

        int _nFrame;
        int _nDirection;
        int currentDirection = 0;

        public int CurrentDirection
        {
            get { return currentDirection; }
            set { currentDirection = value; }
        }
        float timeDelay = 50.0f;

        public float TimeDelay
        {
            get { return timeDelay; }
            set { timeDelay = value; }
        }

        public int NDirection
        {
            get { return _nDirection; }
            set { _nDirection = value; }
        }
        public int NFrame
        {
            get { return _nFrame; }
            set { _nFrame = value; }
        }

        int _currentFrame = 0;

        public int CurrentFrame
        {
            get { return _currentFrame; }
            set { _currentFrame = value; }
        }

        Vector2 pos;

        public Vector2 Pos
        {
            get { return pos; }
            set { pos = value; }
        }

        public MySprite2D(int nFrame, int nDriection, ContentManager Content)
        {
            NFrame = nFrame;
            NDirection = nDriection;

            textures = new Texture2D[_nDirection][];
            for (int i = 0; i < 4; i++)
            {
                textures[i] = new Texture2D[_nFrame];
                for (int j = 0; j < _nFrame; j++)
                {
                    string temp = @"TankImage\Tank\tank" + i.ToString("0") + (j).ToString("00");
                    textures[i][j] = Content.Load<Texture2D>(temp);
                }
            }
        }

        public override void Update(GameTime gameTime)
        {
            CurrentFrame = (int)(gameTime.TotalGameTime.TotalMilliseconds / TimeDelay) % _nFrame;
            base.Update(gameTime);
        }
        public override void Draw(GameTime gameTime, SpriteBatch SBatch)
        {
            SBatch.Begin();
            SBatch.Draw(textures[CurrentDirection][CurrentFrame], pos, Color.White);
            SBatch.End();
        }
    }
}
